//
//  tvView.m
//  GBKHOME
//
//  Created by XMYY-19 on 2017/9/5.
//
//

#import "tvView.h"
#import "LoginController1.h"
#import "WebServices.h"
@interface tvView ()
- (IBAction)c0:(UIButton *)sender;
- (IBAction)c1:(UIButton *)sender;
- (IBAction)c2:(UIButton *)sender;
- (IBAction)c3:(UIButton *)sender;
- (IBAction)c4:(UIButton *)sender;
- (IBAction)c5:(UIButton *)sender;
- (IBAction)c6:(UIButton *)sender;
- (IBAction)c7:(UIButton *)sender;
- (IBAction)c8:(UIButton *)sender;
- (IBAction)c9:(UIButton *)sender;
- (IBAction)delClick:(UIButton *)sender;

@end

@implementation tvView
//-(instancetype)initWithCoder:(NSCoder *)aDecoder
//{
//    if (self = [super initWithCoder:aDecoder]) {
//        UIView *view = [[[NSBundle mainBundle]loadNibNamed:@"tvView" owner:self options:nil]objectAtIndex:0];
//        [self addSubview:view];
//    }
//    return self;
//}
- (void)dealloc {
    [super dealloc];
}

//按钮0
- (IBAction)c0:(UIButton *)sender {
    [self ctrTV:@"0"];
}

//按钮1
- (IBAction)c1:(UIButton *)sender {
    [self ctrTV:@"1"];
}
//按钮1
- (IBAction)c2:(UIButton *)sender {
     [self ctrTV:@"2"];
}
//按钮1
- (IBAction)c3:(UIButton *)sender {
     [self ctrTV:@"3"];
}
//按钮1
- (IBAction)c4:(UIButton *)sender {
     [self ctrTV:@"4"];
}
//按钮1
- (IBAction)c5:(UIButton *)sender {
     [self ctrTV:@"5"];
}
//按钮1
- (IBAction)c6:(UIButton *)sender {
     [self ctrTV:@"6"];
}
//按钮1
- (IBAction)c7:(UIButton *)sender {
     [self ctrTV:@"7"];
}
//按钮1
- (IBAction)c8:(UIButton *)sender {
     [self ctrTV:@"8"];
}
//按钮1
- (IBAction)c9:(UIButton *)sender {
    [self ctrTV:@"9"];
}

- (IBAction)delClick:(UIButton *)sender {
    [UIView animateWithDuration:0.5 animations:^{
        self.frame = CGRectMake(-20, 545, 375, 667);
    }];
}

#pragma mark - 控制TV
- (void)ctrTV:(NSString *)ORDER
{
    NSString *order = ORDER;
    NSString *orderName = NSLocalizedString(order, nil);
    NSString *operat = NSLocalizedString(@"operat:", nil);
    NSString *startTip = [operat stringByAppendingString:orderName];
    [iToast showTip:startTip gravity:iToastGravityBottom];
    
    
    self.ctrOrder = order;
   // NSString *switchId = self.equipment.switchId;
    NSString *switchId = @"8";
    NSString *sessionId = [LoginController1 sessionID];
    NSString *fomat = @"[{\"orderId\":\"%@\", \"switchId\":\"%@\", \"sessionId\":\"%@\"}]";
    NSString *body = [NSString stringWithFormat:fomat, order, switchId, sessionId];
    
    //操作失败！原因：
    NSString *errorTip = [OperationTip operatSuccess:NO type:ErrorTypeNetworkFail];
    [WebServices requestStartOrder:@"ctlTV" body:body target:self action:@selector(ctrTVEnd:) errorTip:errorTip];
}

- (void)ctrTVEnd:(NSDictionary *)dic
{
    NSNumber *result = [dic objectForKey:@"result"];
    if (result.integerValue == 0) {
        //操作成功
        NSString *tip = [OperationTip operatSuccess:YES type:ErrorTypeServerReturnFail];
        [iToast showTip:tip gravity:iToastGravityBottom];
    }
    else
    {
        //操作失败！原因：
        NSString *tip = [OperationTip operatSuccess:NO type:ErrorTypeServerReturnFail];
        [iToast showTip:tip gravity:iToastGravityBottom];
    }
}
@end
